package com.factory.code.controller;


import com.factory.code.controller.param.ProjectPageParam;
import com.factory.code.controller.vo.PageVO;
import com.factory.code.controller.vo.R;
import com.factory.code.repository.ent.ProjectENT;
import com.factory.code.service.ProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("project")
@Api(tags = "项目/工程 管理")
public class ProjectController {

    @Autowired
    private ProjectService projectService;

    @ApiOperation(value = "所有项目")
    @PostMapping("/listAll")
    public R<Object> listAll() {
        List<ProjectENT> projectEnts = projectService.listAll();
        return R.ok(projectEnts);
    }

    @ApiOperation(value = "分页查询项目")
    @PostMapping("/getPage")
    public R<Object> getPage(@RequestBody ProjectPageParam param) {
        PageVO<ProjectENT> page = projectService.getPage(param.getCurrentPage() - 1, param.getPageSize(), param.getName());
        return R.ok(page);
    }

    @ApiOperation(value = "根据id查询项目")
    @PostMapping("/get/{projectId}")
    public R get(@PathVariable("projectId") int projectId) {
        return R.ok(projectService.getById(projectId));
    }


    @ApiOperation(value = "添加项目")
    @PostMapping("/add")
    public R<Object> add(@RequestBody ProjectENT projectENT) {
        return projectService.add(projectENT);
    }

    @ApiOperation(value = "更新项目")
    @PostMapping("/update")
    public R<Object> update(@RequestBody ProjectENT projectENT) {
        return projectService.update(projectENT);
    }

    @ApiOperation(value = "删除项目")
    @PostMapping("/del")
    public R<Object> delete(@RequestBody ProjectENT projectENT) {
        return projectService.delete(projectENT);
    }

    @ApiOperation(value = "复制项目")
    @PostMapping("/copy/{projectId}")
    public R<Object> copy(@PathVariable("projectId") int projectId) {
        return projectService.copy(projectId);
    }


}
